﻿Imports System.Data.OleDb

Public Class WebForm2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim myGUID = Guid.NewGuid()
        Dim newFileName As String = myGUID.ToString() & ".jpg"
        Dim fileLocationOnServerHardDisk = Request.MapPath("pictures") & "/" & newFileName
        f_picture.SaveAs(fileLocationOnServerHardDisk)
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("MyProjectConnection").ConnectionString)
        Dim SqlString As String = "Insert into item(ItemName,description,file, country, category, url, author) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_Itemname.Text)
        cmd.Parameters.AddWithValue("@f2", tb_description.Text)
        cmd.Parameters.AddWithValue("@f3", "pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f4", DD_Country.SelectedValue)
        cmd.Parameters.AddWithValue("@f5", DD_Category.SelectedValue)
        cmd.Parameters.AddWithValue("@f6", tb_url.Text)
        cmd.Parameters.AddWithValue("@f7", User.Identity.Name)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DD_Country.SelectedIndexChanged

    End Sub

    Protected Sub AccessDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles AccessDataSource1.Selecting

    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged1(ByVal sender As Object, ByVal e As EventArgs) Handles DD_Category.SelectedIndexChanged

    End Sub
End Class